<%
    def labelService = grailsApplication.mainContext.getBean("labelService");
    def profileService = grailsApplication.mainContext.getBean("profileService");
    def reportService = grailsApplication.mainContext.getBean("reportService");
%>
<!DOCTYPE html>
<html>
	<head>
		<meta name="layout" content="main"/>
		<title>Pijunn Dashboard</title>
		<style type="text/css" media="screen">
			.status {
				background-color: #eee;
				border: .2em solid #fff;
				margin: 2em 2em 1em;
				padding: 1em;
				width: 12em;
				float: left;
				-moz-box-shadow: 0px 0px 1.25em #ccc;
				-webkit-box-shadow: 0px 0px 1.25em #ccc;
				box-shadow: 0px 0px 1.25em #ccc;
				-moz-border-radius: 0.6em;
				-webkit-border-radius: 0.6em;
				border-radius: 0.6em;
			}
			.table {
				width: 42%;
			}

			.ie6 .status {
				display: inline; /* float double margin fix http://www.positioniseverything.net/explorer/doubled-margin.html */
			}

			.status ul {
				font-size: 0.9em;
				list-style: none;
				margin-bottom: 0.6em;
				padding: 0;
			}
            
			.status li {
				line-height: 1.3;
			}

			.status h1 {
				text-transform: uppercase;
				font-size: 1.1em;
				margin: 0 0 0.8em;
			}
			
			h1.row-label {
				float: left;
				margin: 3em 0;
				clear: both;
			}

			#page-body {
				margin: 2em 1em 1.25em 8em;
			}

			h2 {
				margin-top: 1em;
				margin-bottom: 0.3em;
				font-size: 1em;
			}

			p {
				line-height: 1.5;
				margin: 0.25em 0;
			}

			#controller-list ul {
				list-style-position: inside;
			}

			#controller-list li {
				line-height: 1.3;
				list-style-position: inside;
				margin: 0.25em 0;
			}
			
			.status td {
				color: #636B73;
				font-size: 0.9em;
			}

			@media screen and (max-width: 480px) {
				#status {
					display: none;
				}

				#page-body {
					margin: 0 1em 1em;
				}

				#page-body h1 {
					margin-top: 0;
				}
			}
		</style>
	</head>
	<body>
		<a href="#page-body" class="skip"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
		<div id="page-body" role="main">
			<g:if test="${flash.message}">
				<div class="message" role="status">${flash.message}</div>
			</g:if>
			<h1  class="row-label">Label Summary</h1>
			<div class="status" role="complementary">
				<h1>Label Counts</h1>
				<ul>
					<g:each in="${labelService.getCountsForProperty('type')}" var="type">
					<li>${type[0]} - ${type[1]}</li>
					</g:each>
				</ul>
			</div>
			<div class="status" role="complementary">
				<h1>Registered Counts</h1>
				<ul>
					<g:each in="${labelService.getItemCountsForProperty('type')}" var="type">
					<li>${type[0]} - ${type[1]}</li>
					</g:each>
				</ul>
			</div>
			<div class="status" role="complementary">
				<h1>Claimed/Assigned</h1>
				<ul>
					<g:each in="${labelService.getRegisteredCountsForProperty('type')}" var="type">
					<li>${type[0]} - ${type[1]}</li>
					</g:each>
				</ul>
			</div>

			<h1  class="row-label">User Summary</h1>
			<div class="status" role="complementary">
				<h1>Never Logged In</h1>
				<ul>
					<g:each in="${profileService.getCountsForProperty('passwordExpired')}" var="type">
					<li>${type[0]} - ${type[1]}</li>
					</g:each>
				</ul>
			</div>
			<div class="status" role="complementary">
				<h1>Incomplete Profile</h1>
				<ul>
					<g:each in="${profileService.getIncompletePhoneContactCounts()}" var="type">
					<li>No Phone Entered - ${type}</li>
					</g:each>
				</ul>
			</div>

			<h1  class="row-label">Report Summary</h1>
			<div class="status" role="complementary">
				<h1>Lost Reports</h1>
				<ul>
					<li>Open - ${reportService.countLostReports(true)[0]}</li>
					<li>Closed - ${reportService.countLostReports(false	)[0]}</li>
				</ul>
			</div>
			<div class="status" role="complementary">
				<h1>Found Reports</h1>
				<ul>
				<g:each in="${reportService.countFoundReports('loserRespondTime')}" var="type" status="idx">
					<li>${idx == 0 ? 'Open' : 'Closed'} - ${type}</li>
				</g:each>
				</ul>
			</div>

			<h1  class="row-label"></h1>
			<div class="table status" role="complementary">
				<h1>Lost Reports</h1>
				<table width="50%">
				<thead>
					<th>Label</th>
					<th>Date</th>
					<th>Description</th>
				</thead>
				<tbody>
				<g:each in="${reportService.listOpenLostEvents()}" var="report" status="idx">
					<tr>
						<td>${report.item.label.serialNumber}</td>
						<td>${report.lostTime}</td>
						<td>${report.description} - ${report.location}, ${report.venue}</td>
					</tr>
				</g:each>
				</tbody>
				</table>
			</div>
			<div class="table status" role="complementary">
				<h1>Found Reports</h1>
				<table width="50%">
				<thead>
					<th>Label</th>
					<th>Date</th>
					<th>Description</th>
				</thead>
				<tbody>
				<g:each in="${reportService.listOpenFoundEvents()}" var="report" status="idx">
					<tr>
						<td>${report.item.label.serialNumber}</td>
						<td>${report.foundTime}</td>
						<td>${report.description} - ${report.location}, ${report.venue}</td>
					</tr>
				</g:each>
				</tbody>
				</table>
			</div>
		</div>
	</body>
</html>
